// $codepro.audit.disable
package edu.gatech.team404.junit;

import java.util.ArrayList;

import edu.gatech.team404.Course;
import edu.gatech.team404.Lab;
import edu.gatech.team404.TeamAssignment;
import edu.gatech.team404.dal.IDatabase;
import edu.gatech.team404.dal.LabDAL;
import edu.gatech.team404.tool.Scheduler;
import junit.framework.TestCase;

public class LabDALTest extends TestCase {
	Course course;
	Lab lab1;
	Lab lab2;
	
	LabDAL dal;
	
	protected void setUp() throws Exception {
		course = new Course ("CS 8888", "This is a test course for lab.", "instructor");
		
		lab1 = new Lab (course.getName(), null, "Lab 1", Scheduler.getToday(), Scheduler.getNextWeek(), TeamAssignment.INDIVIDUAL, 4);
		lab2 = new Lab (course.getName(), null, "Lab 2", Scheduler.getToday(), Scheduler.getNextWeek(), TeamAssignment.RANDOM, 4);
		
		dal = new LabDAL();
	}
	
	public void testClearTable () {
		IDatabase db = new IDatabase();
		db.clearTable("LabTable");
		db.clearTable("CourseLabTable");
	}
	
	public void testCreateLab () {
		dal.createLab(lab1);
		dal.createLab(lab2);
		
		assertEquals ("Lab 1", dal.getLabById(lab1.getId()).getName());
		assertEquals ("Lab 2", dal.getLabById(lab2.getId()).getName()); 
	}
	
	public void testGetLabById () {
		assertEquals ("CS 8888", dal.getLabById(lab1.getId()).getCourseName());
		assertEquals (Scheduler.convertToString(Scheduler.getToday()), 
					  Scheduler.convertToString(dal.getLabById(lab2.getId()).getStartDate()));
	}
	
	public void testGetLab () {
		Lab lab = dal.getLab(course.getName(), lab1.getId());
		assertEquals ("Lab 1", lab.getName());
	}
	
	public void testGetAllLabsInCourse () {
		ArrayList<Lab> labs = (ArrayList<Lab>) dal.getAllLabsInCourse(course.getName());
		
		assertEquals(2, labs.size());
		assertEquals ("Lab 2", labs.get(1).getName());
	}
	
	public void testUpdateLab () {
		lab1.setDescription("A new description");
		lab1.setEndDate(Scheduler.getToday());
		lab1.setName("Lab One");
		lab1.setTeamAssignment(TeamAssignment.SELF_SELECT);
		
		dal.updateLab(lab1);
		assertEquals ("Lab One", dal.getLabById(lab1.getId()).getName());
		assertEquals ("A new description", dal.getLabById(lab1.getId()).getDescription());
		assertEquals (Scheduler.convertToString(Scheduler.getToday()), 
					  Scheduler.convertToString(dal.getLabById(lab1.getId()).getEndDate()));
		assertEquals (TeamAssignment.SELF_SELECT.toString(), dal.getLabById(lab1.getId()).getTeamAssignment().toString());
	}
	
	public void testDeleteLab () {
		//dal.deleteLab(lab2.getId());
		//assertNull (dal.getLabById(lab2.getId()));
	}
}
